"""
 encoding    : utf-8
 @File       : login_page.py
 @Author     : sugar 
 @Version    :
 @Description:
 @Date       : 2024/07/10
"""
from auto_code.pages.appraisal_power.cloud_page import *
import time


class Login_pade(Cloud_page):
    """登录"""

    def login(self, user, passwd, yzm):
        """登录"""
        self.driver.find_element("xpath",
                                 "/html/body/div/div/div[1]/form/div[1]/div/div/span/div/input").send_keys(user)

        self.driver.find_element("xpath",
                                 "/html/body/div/div/div[1]/form/div[2]/div/div/span/div/input").send_keys(passwd)
        self.driver.find_element("xpath",
                                 "/html/body/div[1]/div/div[1]/form/div[3]/div/div/span/span/div/input").send_keys(yzm)
        self.driver.find_element("css selector", ".ant-btn").click()
        time.sleep(2)

    def login_rem_pass(self, user, passwd, yzm):
        """记住密码"""
        self.driver.find_element("xpath",
                                 "/html/body/div/div/div[1]/form/div[1]/div/div/span/div/input").send_keys(user)

        self.driver.find_element("xpath",
                                 "/html/body/div/div/div[1]/form/div[2]/div/div/span/div/input").send_keys(passwd)
        self.driver.find_element("xpath",
                                 "/html/body/div[1]/div/div[1]/form/div[3]/div/div/span/span/div/input").send_keys(yzm)
        self.driver.find_element("xpath",
                                 "/html/body/div[1]/div/div[1]/form/div[4]/div/div/span/label/span[1]/input").click()
        self.driver.find_element("css selector", ".ant-btn").click()
        time.sleep(2)
        self.driver.get(r'http://192.168.1.155/cloud/#/open/login')
        self.driver.find_element("xpath",
                                 "/html/body/div[1]/div/div[1]/form/div[3]/div/div/span/span/div/input").send_keys(yzm)
        self.driver.find_element("css selector", ".ant-btn").click()
        time.sleep(2)

    def login_out(self):
        """退出登录"""
        ele = self.driver.find_element("xpath",
                                       "/html/body/div[1]/section/section/header/div/div[2]/span/span[1]").click()
        time.sleep(2)
        self.driver.find_element("css selector",
                                 "li.ant-dropdown-menu-item:nth-child(3)").click()
        time.sleep(2)

    def change_passwd(self, old_passwd, new_passwd, anew_passwd):
        """修改密码"""
        ele = self.driver.find_element("xpath",
                                       "/html/body/div[1]/section/section/header/div/div[2]/span/span[1]").click()
        time.sleep(2)
        self.driver.find_element("css selector",
                                 "li.ant-dropdown-menu-item:nth-child(1)").click()
        time.sleep(2)

        self.driver.find_element("id", "old_pwd").send_keys(old_passwd)
        self.driver.find_element("css selector", "#new_pwd").send_keys(anew_passwd)
        self.driver.find_element("id", "note_pwd").send_keys(anew_passwd)
        self.driver.find_element("css selector", "button.ant-btn:nth-child(1)").click()
        time.sleep(2)

    def clear_user_passwd(self):
        '''清楚登录界面用户名、密码输入框'''
        ele = self.driver.find_element("xpath", "/html/body/div/div/div[1]/form/div[1]/div/div/span/div/input")
        ele.clear()
        ele = self.driver.find_element("xpath", "/html/body/div/div/div[1]/form/div[2]/div/div/span/div/input")
        ele.clear()

    def login_right(self, user):
        """登录成功验证"""
        ele = self.driver.find_element("css selector", "div.right___2rkvB:nth-child(2)")
        text = ele.text
        assert text == "欢迎" + user, "与预期结果不符"

    def login_fail(self):
        """登录失败验证"""
        ele = self.driver.find_element("xpath", "/html/body/div[1]/div/div[1]/div/h1")
        text = ele.text
        assert text == '智慧云猎聘系统', "与预期结果不符"

    def change_passwd_fail(self):
        '''修改密码失败验证'''
        ele = self.driver.find_element("xpath", "/html/body/div[1]/section/section/main/div/div/div/div/button[2]")
        text = ele.text
        assert text == "重置", "与预期结果不符"

    def screenshot(self,name):
        self.driver.get_screenshot_as_file(rf"E:\cloud_test(3)\auto_code\report\picture\{name}.png")
